
/*
	Functions to load localized strings from DLLs generated by RC files

	loadlocalizedstring.cpp

	Translations.com
	October 2007

*/

#include "loadlocalizedstring.h"

#include "../GAME/game.h"

std::string LoadLocalizedString(int rcIndex)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500]; // may need further tweaking, some strings are much larger than others

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	return localizedString;
}

std::string LoadLocalizedString1Variable(int rcIndex, std::string firstString)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500];

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	localizedString.replace( localizedString.find("$1"), 2, firstString);

	return localizedString;
}

std::string LoadLocalizedString2Variables(int rcIndex, std::string firstString,
										  std::string secondString)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500];

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	localizedString.replace( localizedString.find("$1"), 2, firstString);
	localizedString.replace( localizedString.find("$2"), 2, secondString);

	return localizedString;
}

std::string LoadLocalizedString3Variables(int rcIndex, std::string firstString,
										  std::string secondString, std::string thirdString)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500];

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	localizedString.replace( localizedString.find("$1"), 2, firstString);
	localizedString.replace( localizedString.find("$2"), 2, secondString);
	localizedString.replace( localizedString.find("$3"), 2, thirdString);

	return localizedString;
}


std::string LoadLocalizedString4Variables(int rcIndex, std::string firstString,
										  std::string secondString, std::string thirdString,
										  std::string fourthString)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500];

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	localizedString.replace( localizedString.find("$1"), 2, firstString);
	localizedString.replace( localizedString.find("$2"), 2, secondString);
	localizedString.replace( localizedString.find("$3"), 2, thirdString);
	localizedString.replace( localizedString.find("$4"), 2, fourthString);

	return localizedString;
}


std::string LoadLocalizedString5Variables(int rcIndex, std::string firstString,
										  std::string secondString, std::string thirdString,
										  std::string fourthString, std::string fifthString)
{
	std::string localizedString;

	TCHAR charArrayFromRC[500];

	LoadString(CGame::GetLangDLL(), rcIndex, charArrayFromRC, 500);

	localizedString = charArrayFromRC;

	localizedString.replace( localizedString.find("$1"), 2, firstString);
	localizedString.replace( localizedString.find("$2"), 2, secondString);
	localizedString.replace( localizedString.find("$3"), 2, thirdString);
	localizedString.replace( localizedString.find("$4"), 2, fourthString);
	localizedString.replace( localizedString.find("$5"), 2, fifthString);

	return localizedString;
}
